﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeaoBase;
using System.IO.Ports;
using System.Xml;

namespace KeaoDataService
{
    public partial class DuanXin : Form
    {
        public DuanXin()
        {
            InitializeComponent();
        }

        private void menu_btn_shezhi_Click(object sender, EventArgs e)
        {
            KeaoUtils.ConfigSetNodeAttr("网络设备", "地址", cmb_dtu.Text);
            KeaoUtils.ConfigSetNodeAttr("网络设备", "状态", chk_tixing.Checked ? "启用" : "禁用");
            KeaoUtils.ConfigRemoveAllChildNodes("网络设备");
            foreach (string str in lst_shoujihaoma.Items)
            {
                KeaoUtils.ConfigAddChildNodesInnerText("网络设备", "发送号码", str);
            }
            KeaoUtils.ConfigSetNodeAttr("时段", "提醒时间", txt_tixingshijian.Text);
            KeaoUtils.ConfigSetNodeAttr("时段", "日结提醒", chk_tixing.Checked ? "启用" : "禁用");

            KeaoUtils.ShowInfoMessage("配置信息保存完成。");
            DialogResult = DialogResult.OK;

        }

        private void DuanXin_Load(object sender, EventArgs e)
        {
            string[] portStrs = SerialPort.GetPortNames();
            foreach (string str in portStrs)
            {
                cmb_dtu.Items.Add(str);
            }

            cmb_dtu.Text = KeaoUtils.ConfigGetNodeAttr("网络设备", "地址");
            if (KeaoUtils.ConfigGetNodeAttr("网络设备", "类型") == "KeaoNetwok")
            {
                lst_shoujihaoma.Enabled = false;
                cmb_dtu.Enabled = false;
                txt_shoujihaoma.Enabled = false;
                btn_shanchushoujihaoma.Enabled = false;
                btn_tianjiashoujihao.Enabled = false;
                lst_shoujihaoma.Items.Clear();
            }
            else
            {
                XmlNodeList shouJiHao = KeaoUtils.ConfigGetNodeListByTag("发送号码");
                foreach (XmlNode node in shouJiHao)
                {
                    lst_shoujihaoma.Items.Add(node.InnerText);
                }
            }
            txt_tixingshijian.Text = KeaoUtils.ConfigGetNodeAttr("时段", "提醒时间");
            chk_tixing.Checked = KeaoUtils.ConfigGetNodeAttr("时段", "日结提醒") == "启用" ? true : false;


        }
    }
}
